package com.apinji.unionpay.common;

import com.apinji.common.plugin.StrUtils;

/**
 * Created by 轩辕夏夏 on 2017/7/6.
 */
public enum UnionpayErrorCodeEnum {
    SUCCESS("00", "成功"),
    SUCCESS_DEFECT("A6", "有缺陷的成功"),

    CONTECT1("01", "成功 有缺陷的成功 交易失败。详情请咨询95516"),
    CONTECT2("02", "系统未开放或暂时关闭，请稍后再试"),
    CONTECT3("03", "交易通讯超时，请发起查询交易"),
    CONTECT4("04", "交易状态未明，请查询对账结果"),
    CONTECT5("05", "交易已受理，请稍后查询交易结果"),
    CONTECT6("06", "系统繁忙，请稍后再试 "),
    CONTECT10("10", "报文格式错误"),
    CONTECT11("11", "验证签名失败"),
    CONTECT12("12", "重复交易"),
    CONTECT13("13", "报文交易要素缺失"),
    CONTECT14("14", "批量文件格式错误"),
    CONTECT30("30", "交易未通过，请尝试使用其他银联卡支付或联系95516"),
    CONTECT31("31", "商户状态不正确 "),
    CONTECT32("32", "无此交易权限"),
    CONTECT33("33", "交易金额超限"),
    CONTECT34("34", "查无此交易"),
    CONTECT35("35", "原交易不存在或状态不正确"),
    CONTECT36("36", "与原交易信息不符"),
    CONTECT37("37", "已超过最大查询次数或操作过于频繁"),
    CONTECT38("38", "银联风险受限"),
    CONTECT39("39", "交易不在受理时间范围内"),
    CONTECT40("40", "绑定关系检查失败"),
    CONTECT41("41", "批量状态不正确，无法下载"),
    CONTECT42("42", "扣款成功但交易超过规定支付时间"),
    CONTECT43("43", "无此业务权限，详情请咨询95516"),
    CONTECT44("44", "输入号码错误或暂未开通此项业务，详情请咨询95516"),
    CONTECT60("60", "交易失败，详情请咨询您的发卡行"),
    CONTECT61("61", "输入的卡号无效，请确认后输入"),
    CONTECT62("62", "交易失败，发卡银行不支持该商户，请更换其他银行卡"),
    CONTECT63("63", "状态不正确"),
    CONTECT64("64", "卡上的余额不足"),
    CONTECT65("65", "输入的密码、有效期或CVN2有误，交易失败"),
    CONTECT66("66", "持卡人身份信息或手机号输入不正确，验证失败"),
    CONTECT67("67", "密码输入次数超限"),
    CONTECT68("68", "您的银行卡暂不支持该业务，请向您的银行或95516咨询"),
    CONTECT69("69", "您的输入超时，交易失败"),
    CONTECT70("70", "交易已跳转，等待持卡人输入"),
    CONTECT71("71", "动态口令或短信验证码校验失败"),
    CONTECT72("72", "您尚未在{}银行网点柜面或个人网银签约加办银联无卡支付业务，请去柜面或网银开通或拨打{}"),
    CONTECT73("73", "支付卡已超过有效期"),
    CONTECT74("74", "扣款成功，销账未知"),
    CONTECT75("75", "扣款成功，销账失败"),
    CONTECT76("76", "需要验密开通"),
    CONTECT77("77", "银行卡未开通认证支付"),
    CONTECT78("78", "发卡行交易权限受限，详情请咨询您的发卡行"),
    CONTECT79("79", "此卡可用，但发卡行暂不支持短信验证"),
    CONTECT80("80", "交易失败，Token 已过期"),
    CONTECT81("81", "月累计交易笔数(金额)超限"),
    CONTECT82("82", "需要校验密码"),
    CONTECT83("83", "发卡行（渠道）处理中"),
    CONTECT84("84", "需要密码但未上送"),
    CONTECT98("98", "文件不存在"),
    CONTECT99("99", "通用错误")


    ;


    private String code;
    private String msg;

    UnionpayErrorCodeEnum(String code, String msg){
        this.code = code;
        this.msg = msg;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    /**
     * 根据错误码，获得错误信息
     * @param code
     * @return
     */
    public static String getMsg(String code){
        if(StrUtils.isEmpty(code)) {
            return "";
        }
        for(int i = 0; i < UnionpayErrorCodeEnum.values().length; i++) {
            if (UnionpayErrorCodeEnum.values()[i].getCode().equals(code)) {
                return UnionpayErrorCodeEnum.values()[i].getMsg();
            }
        }
        return "Error code not found : " + code;
    }
}
